package Server;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;

import java.awt.FlowLayout;

import javax.swing.JTextField;
import javax.swing.JButton;

import clasesBasicas.MiModelo;
import clasesBasicas.Usuario;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

import javax.swing.JComboBox;

public class Baja extends JFrame {

	private JPanel contentPane;
	JComboBox<String> comboBox = new JComboBox<String>();
	ArrayList <Usuario> listavariables= new ArrayList <Usuario>();
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Baja frame = new Baja();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Baja() {
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 357, 184);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.NORTH);
		
		JLabel lblEliminarUsuario = new JLabel("Eliminar Usuario");
		panel.add(lblEliminarUsuario);
		
		JPanel panel_1 = new JPanel();
		contentPane.add(panel_1, BorderLayout.SOUTH);
		setTitle("Dar de baja");
		JButton btnAceptar = new JButton("Aceptar");
		btnAceptar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Usuario u = new Usuario(0,(String) comboBox.getSelectedItem(),"contrasenya");
				comboBox.removeItem(u.getId_usuario());
				consultasBD.deleteUsuario(u);
				JOptionPane.showMessageDialog(null, "Usuario Eliminado", "Eliminado", JOptionPane.WARNING_MESSAGE);
			}
		});
		panel_1.add(btnAceptar);
		
		JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		panel_1.add(btnCancelar);
		
		JPanel panel_2 = new JPanel();
		contentPane.add(panel_2, BorderLayout.CENTER);
		panel_2.setLayout(null);
		
		JLabel lblIntroducirUsuarioA = new JLabel("Introducir usuario a eliminar:");
		lblIntroducirUsuarioA.setBounds(21, 24, 202, 14);
		panel_2.add(lblIntroducirUsuarioA);
		
		
		comboBox.setBounds(208, 21, 102, 20);
		comboBox.setToolTipText("");
		panel_2.add(comboBox);
		
		
		try {
			listavariables = consultasBD.consultaListaUsuarios();
		} catch (Exception e) {
			e.printStackTrace();
		}
		for(int i=0; i<listavariables.size();i++){
			comboBox.addItem(listavariables.get(i).getId_usuario());
		}
	}

}
